//
//  GC_NothingNoticeView.m
//  OnlineRetailers
//
//  Created by mini3 on 2017/6/7.
//  Copyright © 2017年 OnlineRetailers. All rights reserved.
//

#import "GC_NothingNoticeView.h"

@interface GC_NothingNoticeView ()
///图标
@property(nonatomic, weak) UIImageView *iconImageView;
///提示
@property(nonatomic, weak) UILabel *noticeLabel;
@end

@implementation GC_NothingNoticeView
///初始化
-(id)initWithIsHaveSomething:(BOOL)isHave
{
    self = [super init];
    if(self){
        if(isHave){
            [self initDefaultHaveSomething];
        }else{
            [self initDefault];
        }
    }
    return self;
}

///初始化
-(id)initWithIsHaveSomething:(BOOL)isHave andDesc:(NSString *)desc andIsHeadView:(BOOL)isHeadView
{
    self = [super init];
    if(self){
        if(isHave){
            [self initDefaultHaveSomething];
        }else{
            [self initWithDesc:desc andIsHeadView:isHeadView];
        }
    }
    return self;
}

///初始有
-(void)initDefaultHaveSomething
{
    self.frame = CGRectMake(0, 0, kMainScreenWidth, CGFLOAT_MIN);
}

///初始
-(void)initDefault
{
    self.frame = CGRectMake(0, 0, kMainScreenWidth, HEIGHT_TRANSFORMATION(430));
    self.backgroundColor = [UIColor clearColor];
    
    [self loadSubViewAndConstraints];
}
///初始
- (void)initWithDesc:(NSString *)desc andIsHeadView:(BOOL)isHeadView
{
    self.frame = CGRectMake(0, 0, kMainScreenWidth, HEIGHT_TRANSFORMATION(430));
    self.backgroundColor = [UIColor clearColor];
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        if(isHeadView){
            make.top.equalTo(self).offset(HEIGHT_TRANSFORMATION(100));
        }else{
            make.top.equalTo(self).offset(HEIGHT_TRANSFORMATION(50));
        }
        
    }];
    [self.noticeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.iconImageView.mas_bottom).offset(HEIGHT_TRANSFORMATION(60));
        
    }];
    
    self.noticeLabel.text = desc;
}

///加载子视图及约束
-(void)loadSubViewAndConstraints
{
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self).offset(HEIGHT_TRANSFORMATION(100));
    }];
    [self.noticeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.iconImageView.mas_bottom).offset(HEIGHT_TRANSFORMATION(60));
    }];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
///设置图标
- (void)setIconImageViewForImageName:(NSString *)imageName
{
    [self.iconImageView setImageForName:imageName];
}

///设置提示语句
- (void)setNoticeLabelForNotice:(NSString *)notice
{
    self.noticeLabel.text = notice;
}

#pragma mark -- getter,setter

-(UIImageView*)iconImageView
{
    if(!_iconImageView){
        UIImageView *imageView = [UIImageView createImageViewWithName:@"null_data"];
        imageView.backgroundColor = kCommonWhiteBg;
        [self addSubview:_iconImageView = imageView];
    }
    return _iconImageView;
}

-(UILabel*)noticeLabel
{
    if(!_noticeLabel){
        UILabel *label = [UILabel createLabelWithText:@"暂无内容" font:kFontSize_28 textColor:kFontColorGreen];
        label.backgroundColor = kCommonWhiteBg;
        [self addSubview:_noticeLabel = label];
    }
    return _noticeLabel;
}

@end
